package tech.aistar.day02;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * 本类功能:
 *
 * @author cxylk
 * @date 2020/9/16 18:48
 */
@WebServlet(urlPatterns = "/day02/session/from")
public class SessionCreateAction extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //1.获取httpSession对象
        //1.如果是第一次到达，遇到req.getSession的时候
        //tomcat会分配空间，给定jessionid,保存在cookie,通过
        //响应头信息将cookie返回给client,由client的端保存
        HttpSession session=req.getSession();

        //获取参数
        String name=req.getParameter("name");
        //2.将数据放入到session作用域中
        session.setAttribute("uname",name);

        //3.重定向到其他Servlet
        resp.sendRedirect("/lk/day02/session/to");
    }
}
